package exception;

import javax.servlet.ServletException;
import java.sql.SQLException;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/12/02 19:27
 */


public class CatchException {


    public static void main(String[] args) {
        try {
            new CatchException().demo();
        } catch (ServletException e) {

            System.out.println(e.getCause());
        }
    }
    //捕获并重新抛出异常
    public void demo() throws ServletException {
        try {
            throw new SQLException();
        } catch (SQLException e) {
            ServletException ex = new ServletException("sql error");
            ex.initCause(e);
            throw ex;
        }
    }
}
